package com.hs.gs.vo;

import java.util.List;

import com.hs.gs.domain.Department;
import com.hs.gs.domain.Patrol;
import com.hs.gs.domain.PatrolPoint;
import com.hs.gs.domain.PatrolTime;
import com.hs.gs.exception.IllegalDataProcessException;

public class PatrolOfClockAndDepartmentVO {

	private Department department;
	private PatrolTime clock;
	private int patrolCount;
	private int totalPatrolPointCount;
//	private List<Patrol> patrols;
	
	public PatrolOfClockAndDepartmentVO(List<Patrol> patrols) throws IllegalDataProcessException {
//		this.patrols = patrols;
		if(patrols != null) {
			for(Patrol p : patrols) {
				if(department == null) {
					department = p.getDepartment();
					totalPatrolPointCount = 
						PatrolPoint.findPatrolPointsByDepartment(getDepartment()).getMaxResults();
				} else {
					if(!department.getId().equals(p.getDepartment().getId())) {
						throw new IllegalDataProcessException("Data error! The department...");
					}
				}
				if(clock == null) {
					clock = p.getPTime();
				} else {
					if(!clock.getId().equals(p.getPTime().getId())) {
						throw new IllegalDataProcessException("Data error! The clock...");
					}
				}
				if(Patrol.PatrolStatus.CHECKED.equals(p.getStatus())) {
					patrolCount++;
				}
			}
		}
	}

	public Department getDepartment() {
		return department;
	}
	public PatrolTime getClock() {
		return clock;
	}
	public float getScore() {
		if(totalPatrolPointCount > 0)
			return patrolCount/(float)totalPatrolPointCount*100;
		return 0;
	}
}
